<?php

namespace App\Admin\Controllers;

use App\Admin\Forms\Setting;
use App\Admin\Forms\Step\First;
use App\Admin\Forms\Step\Sec;
use App\Http\Controllers\Controller;
use App\Models\NoticeTemplate;
use App\Models\Site;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\Collapse;
use Encore\Admin\Widgets\InfoBox;
use Encore\Admin\Widgets\Tab;
use Encore\Admin\Widgets\Table;

class HomeController extends Controller
{
    public function index(Content $content)
    {

        $site_count = Site::where(['admin_user_id' => Admin::user()->id])->count();
        $template_count = NoticeTemplate::where(['admin_user_id'=>Admin::user()->id])->count();
        $infoBox = new InfoBox('监听的网站量', 'home', 'blue', '/admin/sites', $site_count);
        $infoBox2 = new InfoBox('模版数量', 'users', 'blue', '/admin/notice-templates', $template_count);
        $content->header('首页');
        $content->description('可以监听网站是否挂');
        $content->row(function (Row $row) use ($infoBox, $infoBox2) {
            $row->column(4, function (Column $column) use ($infoBox) {
                $column->row($infoBox);
            });
            $row->column(4, function (Column $column) use ($infoBox2) {
                $column->row($infoBox2);
            });
        });
        return $content;
    }

    public function indexs(Content $content)
    {
        $forms = [
            'first' => First::class,
            'setting' => Sec::class,
        ];
        $tab = new Tab();
        $tab->add('Pie', 11);
        $tab->add('Table', new Table());
        $tab->add('Text', 'blablablabla....');
        $infoBox = new InfoBox('收入', 'home', 'blue', '/admin/test/setting', '1024');
        $infoBox2 = new InfoBox('浏览量', 'users', 'blue', '/admin/test/setting', '2323k');
        $infoBox = $infoBox->render();
        $tab = $tab->render();
        $collapse = new Collapse();
        $collapse->add('bar', $infoBox);
        $collapse->add('orders', $tab);
        $collapse_html = $collapse->render();
        $base_form = $infoBox;
        return $content->breadcrumb(
            ['text' => '首页', 'url' => '/admin'],
            ['text' => '用户管理', 'url' => '/admin/users'],
            ['text' => '编辑用户']
        )->header('自定义')
            ->description('这个是自定义页面')
            ->row(function (Row $row) use ($base_form, $infoBox, $infoBox2) {
                $row->column(4, function (Column $column) use ($infoBox) {
                    $column->row($infoBox);
                });
                $row->column(4, $infoBox2);
                $row->column(4, function (Column $column) use ($base_form) {
                    $column->row($base_form);
                    $column->row(new Setting());
                    $column->row('333');
                });
            });
    }
}
